<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core_rt" %>
<!DOCTYPE html>
<html>
<head>
    <title>申请维护</title>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">

    <meta name="description" content="">

    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/weui/lib/weui.min.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/weui/css/jquery-weui.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/weui/css/main.css">

</head>

<body ontouchstart>


<header class='demos-header'>
    <h1 class="demos-title">${action=='add'?"添加":"编辑"}申请</h1>
</header>
<form id="form">
    <div class="weui-cells weui-cells_form">

        <input type="hidden" name="id" value="${record.id}">

            <div class="weui-cell">
                <div class="weui-cell__hd"><label class="weui-label">申请原因</label></div>
                <div class="weui-cell__bd">
                    <textarea class="weui-textarea" placeholder="请输入申请原因" rows="3" name="drinkReason" id="drinkReason">${record.drinkReason}</textarea>
                </div>
            </div>

        <div class="weui-cell">
            <div class="weui-cell__hd"><label class="weui-label">饮酒地点</label></div>
            <div class="weui-cell__bd">
                <input class="weui-input" type="text" name="drinkPlace" id="drinkPlace" placeholder="请输入饮酒地点" value="${record.drinkPlace}">
            </div>
        </div>

        <div class="weui-cell">
            <div class="weui-cell__hd"><label for="drinkStartTimes" class="weui-label">饮酒开始时间</label></div>
            <div class="weui-cell__bd">
                <input class="weui-input" type="datetime-local" value="${record.drinkStartTimes}"  name="drinkStartTimes" id="drinkStartTimes" placeholder="">
            </div>
        </div>

        <div class="weui-cell">
            <div class="weui-cell__hd"><label for="drinkEndTimes" class="weui-label">饮酒结束时间</label></div>
            <div class="weui-cell__bd">
                <input class="weui-input" type="datetime-local" value="${record.drinkEndTimes}"  name="drinkEndTimes" id="drinkEndTimes" placeholder="">
            </div>
        </div>

        <div class="weui-cell">
            <div class="weui-cell__hd"><label class="weui-label">紧急联系电话</label></div>
            <div class="weui-cell__bd">
                <input class="weui-input" type="tel" name="emergencyPhone" id="emergencyPhone" value="${record.emergencyPhone}"
                       placeholder="请输入紧急联系电话">
            </div>
        </div>

    </div>
</form>

<div class="weui-btn-area">
    <a class="weui-btn weui-btn_primary" href="javascript:" id="showTooltips">提交</a>
</div>
<div class="weui-tabbar">
    <a href="${pageContext.request.contextPath}/index.do" class="weui-tabbar__item weui-bar__item">
        <div class="weui-tabbar__icon">
            <img src="${pageContext.request.contextPath}/static/weui/images/index.png" alt="">
        </div>
        <p class="weui-tabbar__label">返回首页</p>
    </a>
</div>
<script src="${pageContext.request.contextPath}/static/weui/lib/jquery-2.1.4.js"></script>
<script src="${pageContext.request.contextPath}/static/weui/lib/fastclick.js"></script>
<script>
    $(function () {
        FastClick.attach(document.body);
    });
</script>
<script src="${pageContext.request.contextPath}/static/weui/js/jquery-weui.js"></script>


<script>
    $("#showTooltips").click(function () {
        var drinkReason = $('#drinkReason').val();
        var drinkPlace = $("#drinkPlace").val();
        var emergencyPhone = $("#emergencyPhone").val();
        var drinkStartTime = $("#drinkStartTimes").val();
        var drinkEndTime = $("#drinkEndTimes");
        if (!drinkReason) {
            $.toptip('请输入申请理由');
        } else if (!drinkPlace) {
            $.toptip('请输入饮酒地点');
        } else if (!drinkStartTime) {
            $.toptip('请输入饮酒开始时间');
        } else if (!drinkEndTime) {
            $.toptip('请输入饮酒技术时间');
        } else if (!emergencyPhone || !/1[3|4|5|7|8|9]\d{9}/.test(emergencyPhone)) {
            $.toptip('请输入紧急联系电话');
        } else {
            $.ajax({
                url: '${pageContext.request.contextPath}/apply/saveApply.do',
                data: $("#form").serialize(),
                type: 'post',
                dataType: 'json',
                success: function (data) {
                    if (data.code == '200') {
                        window.location = "${pageContext.request.contextPath}/apply/applyList.do";
                    } else {
                        $.alert(data.msg, "失败");
                    }

                }
            });
        }
    });
</script>
</body>
</html>
